package com.gx.smart.building.ui.assets.fragment

import android.view.ViewGroup
import com.gx.smart.base.BaseMVVMFragmentV2
import com.gx.smart.building.R
import com.gx.smart.building.databinding.FragmentAssetsRunningStateBinding
import com.gx.smart.building.ui.assets.adapter.RunningStateAdapter
import com.gx.smart.building.ui.assets.viewmodel.AssetsViewModel

class AssetsRunningStateFragment : BaseMVVMFragmentV2<AssetsViewModel>() {
    private lateinit var viewBinding: FragmentAssetsRunningStateBinding
    private lateinit var adapter: RunningStateAdapter

    companion object {
        @JvmStatic
        fun newInstance() = AssetsRunningStateFragment()
    }

    override fun onBindLayout(): Int = R.layout.fragment_assets_running_state

    override fun getToolbarTitle(): String = ""

    override fun enableToolbar(): Boolean = false

    override fun onBindViewModel(): Class<AssetsViewModel> = AssetsViewModel::class.java

    override fun initContentView(root: ViewGroup) {
        viewBinding = FragmentAssetsRunningStateBinding.inflate(layoutInflater, root, true)
        adapter = RunningStateAdapter(requireContext())
        viewBinding.recyclerView.adapter = adapter
    }

    override fun initData() {
        val deviceId = requireActivity().intent.getStringExtra("deviceId")
        viewModel.queryDeviceOperateStatus(deviceId!!).observe(viewLifecycleOwner) {
            adapter.addAll(it)
        }
    }
}